﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using easyList.Entities;
using System.IO;

namespace easyList.IO.Reader
{
    class DirPrintReader
    {
        static DirPrintReader instance = null;
        static readonly object padlock = new object();

        DirPrintReader() { }
        public static DirPrintReader Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new DirPrintReader();
                    }
                    return instance;
                }
            }
        }

        public ArchiveObject readDirTxt(string filepath)
        {
            ArchiveObject list = new ArchiveObject();
            string[] lines = System.IO.File.ReadAllLines(filepath);
            //cut each line
            foreach (string currentLine in lines){
                if (currentLine.Length > 39 && !currentLine.Contains("<DIR>") && !currentLine.Contains(" bytes") ){
                    string tmpLine = currentLine.Substring(39,currentLine.Length-39);
                    FileObject currentFileObject = new FileObject();
                    currentFileObject.filename = tmpLine;
                    currentFileObject.storeID = Path.GetFileNameWithoutExtension(filepath);
                    list.addFileObject(currentFileObject);
                }
            }
            return list;
        }

    }
}
